package com.jun;

/**
 * 斐波那契
 * 01-复杂度
 */
public class Main {
    //plus一
    public static int plus(int n) {
        if (n <= 1) {
            return n;
        }
        return plus(n - 1) + plus(n - 2);
    }


    //plus 2
    public static int plus2(int n) {
        if (n <= 1) {
            return n;
        }
        int first = 0;
        int second = 1;
        for (int i = 0; i < (n - 1); i++) {
            int sum = first + second;
            first = second;
            second = sum;
        }
        return second;

    }

    public static int plus3(int n) {
        if (n < 2) {
            return n;
        }

        int first = 0;
        int second = 1;
        for (int i = 2; i <=n ; i++) {
            second = first +second;
            first = second - first;
        }

        return second;
    }

    // 0 1 1 2 3 5
    public static void main(String[] args) {
        System.out.println(plus(4));
        System.out.println(plus2(4));
        System.out.println(plus3(4));

    }
}
